package ist.utl.pt.smartfleet.stationterminal.rest.webservice.station;

import ist.utl.pt.smartfleet.stationterminal.rest.webservice.client.RestClient;
import ist.utl.pt.smartfleet.stationterminal.station.Station;
import ist.utl.pt.smartfleet.stationterminal.util.parser.SmartFleetParser;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

public class StationWebServiceUtil {
	
	static final String SERVICE_URL = "/smartfleetcserver/web/services/stationws";
	static final String SAVE_METHOD = "/startup";
	static final String ONLINE_STATIONS_METHOD = "/get/stations/state/";

	public static Station getStationInfo(String id) {
		String url = SERVICE_URL+SAVE_METHOD+"/"+id;

		Station station = null;
		try {
			String response = RestClient.doGet(url);
			station = SmartFleetParser.toStation(response);

		} catch (Exception e) {
			Log.d("Error: ", e.getMessage());
		}

		return station;

	} //

	public static List<Station> getOnLineStations() {
		String url = SERVICE_URL+ONLINE_STATIONS_METHOD+"on";
		List<Station> list = null;
		
		try {
			String response = RestClient.doGet(url);
			System.out.println(response);
			list = SmartFleetParser.getOnlineStations(response);

		} catch (Exception e) {
			Log.d("Error: ", e.getMessage());
		}

		return list;

	} //

	
	public static void updateStationState(int idStation, String state) {

		String url = "/stationws/update/state/";

		try {

			String response = RestClient.doGet(url + idStation + "/" + state);
			System.out.println(response);
			
		} catch (Exception e) {
			Log.d("Error: ", e.getMessage());
		}

	} //
}
